package com.quasar.hpatient.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quasar.hpatient.R;


public class WidgetTitle extends LinearLayout {

    private Drawable icons;

    public WidgetTitle(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    TextView title;
    ImageView icon;

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.widget_title, this);
        title = (TextView) findViewById(R.id.title);
        icon = (ImageView) findViewById(R.id.icon);

        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.WidgetTitle);

        String mtitle = a.getString(R.styleable.WidgetTitle_title_title);
        if (mtitle != null) {
            title.setText(mtitle);
        }
        if (a.hasValue(R.styleable.WidgetTitle_title_icon)) {
            icons = a.getDrawable(
                    R.styleable.WidgetTitle_title_icon);
            icons.setCallback(this);
        }
        a.recycle();
        if (icons!=null){
            icon.setImageDrawable(icons);
        }
    }
}
